<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../../plugins/mui/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/chineseHospital/section.css" />
		<script src="../../js/statistics.js"></script>
		<style>
			.header a{
				color:#fff;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title"></h1>
			<a class="arrange">一周排班</a>
		</header>
		<div class="body">
			<div class="list">
				
			</div>
		</div>
		<div class="modal-box" style="display: none;">
			<div class="modal">
				<p>请选择就诊日期</p>
				<div class="date">
					<ul>
						
					</ul>
				</div>
				<div class="foot">
					<ul>
						<li id="cancel">取消</li>
						<li id="check">确定</li>
					</ul>
				</div>
			</div>
			
		</div>
		<script src='../../plugins/jquery/jquery-3.1.0.min.js'></script>
		<script src="../../plugins/mui/mui.min.js"></script>
		<script src="../../js/getApiToken.js"></script>
		<script src='../../plugins/template/template.js'></script>
		<script type="text/javascript" src="../../js/md5.js" ></script>
		<script src='../../plugins/fontset/fontset.js'></script>
		<script type="text/html" id="list">
			<ul>
				{{each data as value index}}
				<li data-id="{{value.iysbm}}">
					<div class="up">
						<span>{{value.name}}</span>
						<!--<span>{{value.czc}}</span>-->
						{{if value.number > 9}}
						<span>余号：<i class="lot">{{value.number}}</i></span>
						{{else}}
						<span>余号：<i class="less">{{value.number}}</i></span>
						{{/if}}
					</div>
					<div class="down">
						<span>溧阳市中医院</span>
						<span>{{value.cksmc}}</span>
					</div>
				</li>
				{{/each}}
			</ul>
		</script>
		<script type="text/javascript">
			mui.init();
			
			mui.plusReady(function(){
				var ksbm = plus.webview.currentWebview().ksbm,
					ksmc = plus.webview.currentWebview().ksmc;
					console.log(ksbm)
					$(".header>h1").text(ksmc);
				myAjax('home/Hospital_service/doctorList','get',{'cksbm':ksbm},function(data){
					console.log(JSON.stringify(data))
					if(data.code == 1){
						initList(data.data);
					}
				})
				$("#check").on('tap',function(){
					$(".date").find('li').each(function(key,e){
						if($(this).hasClass('active')){
							var date = new Date(),
								newDay = date.getTime() + key * 24 * 60 * 60 * 1000;
								console.log(parseInt(newDay/1000))
							myAjax('home/Hospital_service/doctorList','get',{'cksbm':ksbm,'dpbrq':parseInt(newDay/1000)},function(data){
								console.log(JSON.stringify(data))
								if(data.code == 1){
									$(".modal-box").hide();
									if(data.data == '' || !data.data){
										mui.toast('当天没有医生排班');
									}
									initList(data.data)
								}
							})
						}
					})
				});
				mui(".list").on('tap','li',function(event){
					var ysbm = $(this).attr('data-id');
					mui.openWindow({
						url:'doctor.html',
						id:'doctor.html',
						extras:{
							'ysbm':ysbm,
							'ksmc':ksmc
						}
					})
				})
			});
			$(function(){
				for(var i = 0;i < 6 ;i++){
					var myDate = new Date(),
						weeks = ['周日','周一','周二','周三','周四','周五','周六']
					myDate.setTime(myDate.getTime() + i * 24 * 60 * 60 * 1000);
					var	newDate = myDate.getFullYear()+"-" + (myDate.getMonth()+1) + "-" + myDate.getDate(),
						week = myDate.getDay();
					if(i == 0){
						var html = '<li class="active">'+ newDate +' '+ weeks[week] +'<span><i></i></span></li>';
					}else{
						var html = '<li>'+ newDate +' '+ weeks[week] +'<span><i></i></span></li>';
					}
					$(".date ul").append(html);
				}
//				var newYear = year.replace(/\//g,'-');
				
				$(".date").delegate('li','tap',function(){
					$(this).addClass('active').siblings().removeClass('active');
				});
				$(".arrange").on('tap',function(){
					$(".modal-box").show();
				})
				$("#cancel").on('tap',function(){
					$(".modal-box").hide();
				});
			})
			function initList(data){
				var list = {
					data:data
				};
				var html = template('list',list);
				$(".list").empty().html(html);
			}
		</script>
	</body>
</html>